package com.hwd.srb.core.controller.admin;


import com.hwd.srb.common.result.R;
import com.hwd.srb.core.pojo.entity.BorrowInfo;
import com.hwd.srb.core.pojo.vo.BorrowInfoApprovalVO;
import com.hwd.srb.core.service.BorrowInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author 黄伟东/Victor
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/admin/core/borrowInfo")
@Api(tags = "借款信息后台管理")
public class AdminBorrowInfoController {

    @Resource
    private BorrowInfoService borrowInfoService;

    /**
     * 获取借款审核对象，进行审核
     * （插入数据，考虑幂等性），事物控制
     * 审核通过后：
     *  1）修改借款申请状态(borrow_info表)
     *  2）创建标的lend标的数据结构(lend表)
     * @param borrowInfoApprovalVO 借款审核对象
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("借款申请审核")
    @PostMapping("/approval")
    public R approval(@ApiParam(value = "借款审核对象", required = true)
                          @RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO) {
        borrowInfoService.approval(borrowInfoApprovalVO);

        return R.ok().message("审核提交成功");
    }

    /**
     * 根据借款信息id获取借款信息
     *
     * @param borrowInfoId 借款信息id
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("获取借款信息")
    @GetMapping("/show/{id}")
    public R show(@ApiParam(value = "借款人id", required = true, example = "1") @PathVariable("id") Long borrowInfoId) {

        Map<String, Object> borrowInfoDetail = borrowInfoService.show(borrowInfoId);

        return R.ok().data("borrowInfoDetail", borrowInfoDetail);
    }

    /**
     * 借款信息列表
     *
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("借款信息列表")
    @GetMapping("/list")
    public R list() {
        // 调用业务层增删改查
        List<BorrowInfo> borrowInfoList = borrowInfoService.selectList();
        return R.ok().data("list", borrowInfoList);
    }
}

